import type { FcPageConfig } from '@/types/fcform'
import { createColums } from './table/columns.ts'
import { createFormItems } from './edit/formItems.ts'
import { createRules } from './edit/rules.ts'
export function usePageConfig(): FcPageConfig {
  return {
    KEY: 'id',
    pageProps: {
      tools: {
        add: {
          auth: 'sys_menu_add',
        },
      },
    },
    table: {
      isPaging: false,
      getApi: '/admin/menu/tree',
      delApi: {
        api: '/admin/menu',
        method: 'delete',
        path: true,
      },
      createColums,
    },
    edit: {
      default: {
        addApi: '/admin/menu',
        editApi: {
          api: '/admin/menu',
          method: 'put',
        },
        defaultValue: {
          parentId: '-1',
          sortOrder: 1,
          menuType: '0',
          name: '',
          enName: '',
          path: '',
          component: 'Layout',
          permission: '',
          keepAlive: false,
          showNext: true,
          icon: '',
        },
        saveParams: (params) => {
          params.keepAlive = params.keepAlive ? '1' : '0'
          if (params?.id) {
            params.menuId = params.id
            delete params.children
            delete params.id
            delete params.meta
          }
          return params
        },
        createItems: createFormItems,
        createRule: createRules,
      },
    },
  }
}
